<!--
 * @Author: Dorange.Wang
 * @Date: 2021-04-07 14:14:53
 * @LastEditors: your name
 * @LastEditTime: 2021-11-19 17:57:44
 * @Description: file content
-->
<route>
{
  "meta":{
    "title": "组织架构",
    "showMenu" :true,
    "envHide": "PORTAL",
    "serialNum": 10,
    "localism": "sys.organizational_structure"
  }
}
</route>
<template>
  <div style="height: calc(100%)">
    <el-row :gutter="24" class="pht100">
      <el-col
        :span="4"
        class="pht100 ovya ovhx"
        style="border-right: 1px solid #dcdfe6"
      >
        <ResizableGrid :handleStyle="{ transform: 'translateX(14px)' }">
          <el-tree
            ref="tree"
            class="custom-tree custom-tree--highlight-current pht100"
            :data="orgTree"
            :expand-on-click-node="false"
            node-key="id"
            highlight-current
            :default-expanded-keys="expandedOrg"
            :current-node-key="currentOrg"
            @node-click="handleOrgClick"
            @node-expand="handleOrgExpand"
            @node-collapse="handleOrgCollapse"
          >
            <span
              class="custom-tree__node"
              :class="{
                'custom-tree-select__is-disabled':
                  data.accessLevel === 'ReadOnly',
              }"
              slot-scope="{ node, data }"
            >
              <span :title="data.name" class="custom-tree__span">{{
                data.name
              }}</span>
              <el-dropdown
                placement="bottom"
                v-if="data.accessLevel !== 'ReadOnly'"
                @command="handleOrgCommand($event, data)"
              >
                <i class="el-icon-more" />
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item
                    v-permission:system_org__dept_add
                    command="create"
                    icon="el-icon-plus"
                    >{{ $t("sys.new_sub_department") }}</el-dropdown-item
                  >
                  <el-dropdown-item
                    v-permission:system_org__dept_edit
                    command="edit"
                    icon="el-icon-edit"
                    >{{ $t("sys.edit_department") }}</el-dropdown-item
                  >
                  <el-dropdown-item
                    v-permission:system_org__dept_delete
                    :disabled="data.parentId === defaultConfig.root"
                    command="delete"
                    icon="el-icon-delete"
                    >{{ $t("sys.delete_department")
                    }}{{ node.parentId }}</el-dropdown-item
                  >
                  <el-dropdown-item
                    v-permission:system_org__dept_edit
                    divided
                    :disabled="
                      data.parentId === defaultConfig.root || data._isFirst
                    "
                    command="up"
                    icon="el-icon-arrow-up"
                    >{{ $t("sys.move_up") }}</el-dropdown-item
                  >
                  <el-dropdown-item
                    v-permission:system_org__dept_edit
                    :disabled="
                      data.parentId === defaultConfig.root || data._isLast
                    "
                    command="down"
                    icon="el-icon-arrow-down"
                    >{{ $t("sys.move_down") }}</el-dropdown-item
                  >
                </el-dropdown-menu>
              </el-dropdown>
            </span>
          </el-tree>
        </ResizableGrid>
      </el-col>

      <el-col :span="20" class="pht100 ovya">
        <el-row :gutter="12">
          <el-col :span="6">
            <el-input
              v-model="queryData.name"
              :placeholder="$t('sys.name')"
              clearable
              :maxlength="64"
              prefix-icon="el-icon-search"
            />
          </el-col>
          <el-col :span="6">
            <el-input
              v-model="queryData.username"
              :placeholder="$t('sys.account_number')"
              clearable
              :maxlength="64"
              prefix-icon="el-icon-search"
            />
          </el-col>
          <el-col :span="6">
            <el-input
              v-model="queryData.jobNumber"
              :placeholder="$t('sys.job_number')"
              clearable
              :maxlength="32"
              prefix-icon="el-icon-search"
            />
          </el-col>
          <el-col :span="6">
            <el-input
              v-model="queryData.mobile"
              :placeholder="$t('sys.cellphone_number')"
              clearable
              :maxlength="11"
              prefix-icon="el-icon-search"
            />
          </el-col>
          <el-col :span="6" class="mt10">
            <el-input
              v-model="queryData.email"
              :placeholder="$t('sys.email')"
              clearable
              :maxlength="128"
              prefix-icon="el-icon-search"
            />
          </el-col>
          <el-col :span="6" class="mt10">
            <el-select
              v-model="queryData.status"
              :placeholder="$t('sys.status')"
              style="width: 100%"
              clearable
            >
              <el-option
                v-for="item in USER_STATUS_ENUM"
                :key="item.key"
                :value="item.key"
                :label="$t('sys.' + item.i18nLable)"
              >
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="6" class="mt10" v-if="VUE_APP_ROOT_URL === './'">
            <el-select
              v-model="queryData.seat"
              :placeholder="$t('sys.user_seat')"
              style="width: 100%"
              clearable
            >
              <el-option
                v-for="item in USER_SEAT_STATUS_ENUM"
                :key="item.key"
                :value="item.key"
                :label="$t('sys.' + item.i18nLable)"
              >
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="6" class="mt10">
            <el-button type="primary" @click="loadUserData">{{
              $t("sys.query")
            }}</el-button>
            <el-button @click="handleReset">{{ $t("sys.reset") }}</el-button>
          </el-col>
          <el-col :span="24" class="mt10">
            <el-button
              v-permission:system_org__user_add
              type="primary"
              size="small"
              @click="handleCreate"
              >{{ $t("sys.new") }}</el-button
            >

            <CommonImport
              v-permission:system_org__user_import
              ref="CommonImport"
              style="display: inline-block; margin-left: 10px"
              :importApi="postHmuserImport"
              :importUrl="`/api/hmuser/import`"
              :queryParams="{
                orgId: this.currentOrg,
              }"
              @ok="handleImportOk"
            >
              <el-button-group>
                <el-button type="primary" icon="el-icon-upload2">{{
                  $t("sys.import")
                }}</el-button>
                <el-button
                  type="primary"
                  icon="el-icon-download"
                  :title="$t('sys.import_template_download')"
                  @click.stop="handleTemplateDownload"
                ></el-button>
              </el-button-group>
            </CommonImport>

            <el-button
              v-permission:system_org__user_export
              style="margin-left: 10px"
              type="primary"
              size="small"
              @click="handleExport"
              >{{ $t("sys.export") }}</el-button
            >

            <el-dropdown
              style="margin-left: 10px"
              @command="handleUserBatchCommand"
            >
              <el-button
                >{{ $t("sys.batch_operation")
                }}<i class="el-icon-arrow-down el-icon--right"></i
              ></el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                  :disabled="userSelected.length === 0 || batchStatus.hasLeaved"
                  command="quit"
                  icon="el-icon-user"
                  v-permission:system_org__user_leave
                  >{{ $t("sys.quit") }}</el-dropdown-item
                >
                <el-dropdown-item
                  v-permission:system_org__user_delete
                  :disabled="userSelected.length === 0"
                  command="delete"
                  icon="el-icon-delete"
                  >{{ $t("sys.delete") }}</el-dropdown-item
                >
                <el-dropdown-item
                  v-permission:system_org__user_edit
                  :disabled="userSelected.length === 0 || batchStatus.hasLeaved"
                  command="reset"
                  icon="el-icon-setting"
                  >{{ $t("sys.reset_password") }}</el-dropdown-item
                >
                <el-dropdown-item
                  v-permission:system_org__user_edit
                  :disabled="
                    userSelected.length === 0 ||
                    batchStatus.hasLeaved ||
                    batchStatus.orgExcepted
                  "
                  command="move"
                  icon="el-icon-position"
                  >{{ $t("sys.transfer_to_department") }}</el-dropdown-item
                >
                <el-dropdown-item
                  v-permission:system_org__user_edit
                  :disabled="userSelected.length === 0 || batchStatus.hasLeaved"
                  command="higher"
                  icon="el-icon-s-custom"
                  >{{ $t("sys.set_up_superior") }}</el-dropdown-item
                >
              </el-dropdown-menu>
            </el-dropdown>

            <el-dropdown
              placement="bottom-start"
              style="margin-left: 10px"
              @command="handleUserBatchCommand"
              v-if="
                VUE_APP_ROOT_URL === './' &&
                getAuthCenterInfo.status !== 'TRIAL'
              "
              v-permission="[
                'system_org__user_grant_seat',
                'system_org__user_cancel_seat',
              ]"
            >
              <el-button
                >{{ $t("sys.user_seat")
                }}<span>{{
                  "（" +
                  (getAuthCenterInfo.usedSeat||0) +
                  "/" +
                  (getAuthCenterInfo.seatTotal||0) +
                  "）"
                }}</span>
                <i class="el-icon-arrow-down el-icon--right"></i
              ></el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                  v-permission:system_org__user_grant_seat
                  :disabled="
                    userSelected.length === 0 ||
                    userSelected.length > getAuthCenterInfo.unUsedSeat ||
                    batchStatus.hasSeat
                  "
                  command="grantSeat"
                  >{{ $t("sys.granting_a_user_seat") }}</el-dropdown-item
                >
                <el-dropdown-item
                  v-permission:system_org__user_cancel_seat
                  :disabled="
                    getAuthCenterInfo.usedSeat === 0 ||
                    userSelected.length === 0 ||
                    !batchStatus.hasSeat
                  "
                  command="cancelSeat"
                  >{{ $t("sys.cancel_user_seat") }}</el-dropdown-item
                >
              </el-dropdown-menu>
            </el-dropdown>
            <el-dropdown
              placement="bottom-start"
              v-permission:system_org__password_check
              style="float: right; padding: 9px 15px"
              :hide-on-click="false"
            >
              <i class="el-icon-setting f18 poi"></i>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                  style="border-bottom: 1px solid #ebeef5; text-align: center"
                  >{{
                    $t("sys.organizational_structure_setting")
                  }}</el-dropdown-item
                >
                <el-dropdown-item>
                  <el-checkbox-group
                    v-model="checkList"
                    @change="changeCheckList"
                  >
                    <el-checkbox label="pwdCheck">{{
                      $t("sys.password_strength_verification")
                    }}</el-checkbox>
                  </el-checkbox-group></el-dropdown-item
                >
              </el-dropdown-menu>
            </el-dropdown>
          </el-col>
        </el-row>

        <el-table
          row-key="id"
          ref="table"
          class="mt10"
          :data="tableData"
          v-loading="loading"
          style="width: 100%"
          current-row-key="id"
          stripe
          border
          @selection-change="handleUserSelect"
        >
          <el-table-column align="center" type="selection" width="50">
          </el-table-column>
          <el-table-column prop="name" :label="$t('sys.name')">
            <template slot-scope="scope">
              {{ scope.row.name }}
              <el-tooltip
                v-if="
                  scope.row.manageOrg &&
                  scope.row.manageOrg.includes('[' + currentOrg + ']')
                "
                style="
                  position: relative;
                  top: -1px;
                  margin-left: 3px;
                  vertical-align: text-bottom;
                "
                effect="dark"
                :content="$t('sys.department_head')"
                placement="top"
              >
                <IconPark size="14" type="permissions" fill="#999" />
              </el-tooltip>
              <!-- <span v-if="scope.row.manageOrg && scope.row.manageOrg.includes('['+currentOrg+']')" class="dept-manager--desc"> · 部门负责人</span> -->
            </template>
          </el-table-column>
          <el-table-column prop="username" :label="$t('sys.account_number')" />
          <el-table-column prop="jobNumber" :label="$t('sys.job_number')" />
          <el-table-column prop="mobile" :label="$t('sys.cellphone_number')" />
          <el-table-column prop="telephone" :label="$t('sys.landline')" />
          <el-table-column prop="email" :label="$t('sys.email')" />
          <el-table-column prop="status" :label="$t('sys.status')">
            <template slot-scope="scope">
              <el-badge
                class="user-status-badge"
                is-dot
                :type="scope.row.status | userStatusBadge"
              />{{ scope.row.status | userStatus }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="VUE_APP_ROOT_URL === './'"
            prop="seatUid"
            :label="$t('sys.user_seat')"
          >
            <template slot-scope="scope">
              {{ scope.row.seatUid ? $t("sys.yes") : $t("sys.no") }}
            </template>
          </el-table-column>
          <!-- <el-table-column prop="orgNameList" label="所属部门">
          <template slot-scope="scope">
            <div class="org-name-list">
              <el-tag type="info" v-for="(org,index) in scope.row.orgNameList" :key="index">{{ org }}</el-tag>
            </div>
          </template>
        </el-table-column> -->
          <el-table-column prop="orgNameList" :label="$t('sys.department')">
            <template slot-scope="scope">
              <div
                class="org-name-tag"
                v-for="(org, index) in scope.row.orgNameList"
                :key="index"
                :title="org"
              >
                {{ org }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="actions" :label="$t('sys.operation')">
            <template slot-scope="scope">
              <!-- <span
                class="table-actionItem"
                v-permission:system_org__user_edit
              ><el-button
                type="text"
                @click="handleSort(scope.row)"
              >排序</el-button
              ></span
              > -->
              <span class="table-actionItem" v-permission:system_org__user_edit
                ><el-button type="text" @click="handleEdit(scope.row)">{{
                  $t("sys.edit")
                }}</el-button></span
              >
              <span
                class="table-actionItem"
                v-permission:system_org__user_delete
              >
                <el-popconfirm
                  :title="$t('sys.confirm_to_delete_person')"
                  placement="top"
                  @confirm="handleDelete(scope.row)"
                >
                  <el-button class="link-danger" type="text" slot="reference">{{
                    $t("sys.delete")
                  }}</el-button>
                </el-popconfirm>
              </span>
            </template>
          </el-table-column>
        </el-table>
        <div class="tr mt24">
          <x-pagination
            :total="total"
            :pageSize.sync="pageData.pageSize"
            :pageNo.sync="pageData.pageNo"
            @search="loadUserData"
          />
        </div>
      </el-col>

      <org-form
        ref="orgForm"
        :treeData="orgTree"
        :defaultConfig="defaultConfig"
        @ok="loadOrgData"
      />

      <sort-form ref="sortForm" @ok="loadUserData" />

      <move-form ref="moveForm" :treeData="orgTree" @ok="loadUserData" />

      <select-modal
        itemRadio
        :title="$t('sys.select_superior')"
        :autoClose="false"
        ref="SelectHigherModal"
        :treeData="orgTree"
        :treeNodeChange="handleSelectHigherNodeChange"
        :disabledNodeKeys="disabledNodeKeys"
        :disabledItemKeys="userSelected.map((item) => item.id)"
        @ok="handleHigherChange"
      >
      </select-modal>
    </el-row>
  </div>
</template>

<script>
import i18n from "../../../../i18n"
import { Confirm } from "@/utils/decorator"
import { USER_STATUS_ENUM, USER_SEAT_STATUS_ENUM } from "@/utils/enum"
import { arrayToTree, downloadFileStream, breadFirstTree } from "@/utils/util"

import { IconPark } from "@icon-park/vue/es/all"

import {
  getHmorgListwithpermission,
  putHmorgUp,
  putHmorgDown,
  deleteHmorg,
} from "@/apis/paas/HmOrgController.js"
import {
  getHmuserPageListwithpermission,
  deleteHmuser,
  putHmuserQuit,
  putHmuserResetpsd,
  putHmuserResethigher,
  postHmuserImport,
  getHmuserExport,
  getHmuserDownloadexcel,
} from "@/apis/paas/HmUserController.js"
import { unbindSeatUids, distributionSeatUids } from "@/customApi/license.js"
import OrgForm from "./__components__/OrgForm"
import SortForm from "./__components__/SortForm"
import MoveForm from "./__components__/MoveForm"
import SelectModal from "@/components/SelectModal"
import ResizableGrid from "@/components/ResizableGrid"
import CommonImport from "@/components/CommonImport"
import { putHmtenantappNakedPwdcheck } from "@/apis/dev-centre/HmTenantAppController.js"
import { appUnique } from "@/utils/auth"
import { mapGetters, mapActions } from "vuex"

const defaultQueryData = {
  status: USER_STATUS_ENUM[0].key,
}

const defaultConfig = {
  root: 0,
}

export default {
  name: "Organization",
  components: {
    OrgForm,
    SortForm,
    MoveForm,
    SelectModal,
    ResizableGrid,
    CommonImport,
    IconPark,
  },
  data() {
    return {
      USER_STATUS_ENUM,
      USER_SEAT_STATUS_ENUM,
      defaultConfig,
      orgList: [],
      orgTree: [],
      disabledNodeKeys: [],
      expandedOrg: [],
      currentOrg: undefined,
      loading: false,
      queryData: {
        ...defaultQueryData,
      },
      pageData: {
        pageSize: 10,
        pageNo: 1,
      },
      tableData: [],
      total: 0,
      userSelected: [],
      visible: false,
      checkList: [],
      VUE_APP_ROOT_URL: process.env.VUE_APP_ROOT_URL,
    }
  },

  computed: {
    ...mapGetters(["APP_INFO", "getAuthCenterInfo"]),
    // 批量选择人员中是否有离职的、非当前部门的人员
    batchStatus() {
      return {
        hasLeaved: this.userSelected.some((item) => item.status !== 1),
        orgExcepted: this.userSelected.some(
          (item) => !item.orgIds.includes(this.currentOrg)
        ),
        hasSeat: this.userSelected.some((item) => !!item.seatUid),
      }
    },
  },

  async created() {
    if (this.VUE_APP_ROOT_URL === "./") {
      await this.$store.dispatch("GetLicenseInfoDto")
    }
    this.loadOrgData()
    if (this.APP_INFO.pwdCheck) {
      this.checkList.push("pwdCheck")
    }
  },
  watch: {
    expandedOrg: function (val) {
      this.$router.replace({
        ...this.$route,
        query: {
          ...this.$route.query,
          expandedOrg: JSON.stringify(this.expandedOrg),
        },
      })
    },

    currentOrg: function (val) {
      this.$router.replace({
        ...this.$route,
        query: {
          ...this.$route.query,
          currentOrg: val,
        },
      })
    },
  },

  methods: {
    ...mapActions(["LOAD_APP_INFO"]),
    changeCheckList(data) {
      let params = {
        appUniqueId: appUnique,
        pwdCheck: "",
      }
      params.pwdCheck = data.includes("pwdCheck")
      putHmtenantappNakedPwdcheck(params).then((res) => {
        this.LOAD_APP_INFO()
      })
    },
    postHmuserImport,
    findFirstNodeCanClick(tree) {
      let firstNode
      breadFirstTree(
        tree,
        (node) => {
          if (node.accessLevel !== "ReadOnly") {
            firstNode = node
            return false
          }
          return true
        },
        "children"
      )
      return firstNode
    },
    loadOrgData() {
      const { expandedOrg, currentOrg } = this.$route.query
      this.currentOrg = currentOrg ? Number(currentOrg) : undefined
      this.expandedOrg = expandedOrg ? JSON.parse(expandedOrg) : []
      getHmorgListwithpermission().then((res) => {
        this.orgList = res
        this.disabledNodeKeys = this.orgList
          .filter((i) => i.accessLevel === "ReadOnly")
          .map((i) => i.id)
        this.orgTree = arrayToTree(res)
        const nodeCanClick = this.findFirstNodeCanClick(this.orgTree)
        if (this.expandedOrg.length === 0 && this.orgTree.length > 0) {
          this.expandedOrg = [nodeCanClick?.id]
        }
        if (!this.currentOrg && this.orgTree.length > 0) {
          if (nodeCanClick && nodeCanClick.id) {
            this.currentOrg = nodeCanClick.id
          } else {
            this.currentOrg = undefined
          }
        } else {
          const node = this.orgList.filter((i) => i.id === this.currentOrg)[0]
          if (!node || node.accessLevel === "ReadOnly") {
            if (nodeCanClick && nodeCanClick.id) {
              this.currentOrg = nodeCanClick.id
            } else {
              this.currentOrg = undefined
            }
          }
        }
        this.$nextTick(() => {
          this.$refs.tree.setCurrentKey(this.currentOrg)
          const nodeData = this.orgList.find(
            (item) => item.id === this.currentOrg
          )
          this.handleOrgClick(nodeData)
        })
      })
    },

    handleOrgCommand(command, data) {
      if (command === "create") {
        this.handleOrgCreate(data)
      } else if (command === "up" || command === "down") {
        this.handleOrgMove(data, command)
      } else if (command === "edit") {
        this.handleOrgEdit(data)
      } else if (command === "delete") {
        this.handleOrgDelete(data)
      }
    },

    handleOrgCreate(data) {
      this.$refs.orgForm.addForm({
        parentId: data.id,
      })
    },

    handleOrgMove(data, command) {
      const request = command === "up" ? putHmorgUp : putHmorgDown
      request({
        id: data.id,
      }).then(() => {
        this.loadOrgData()
      })
    },

    handleOrgExpand(data) {
      const { id } = data
      this.expandedOrg.push(id)
    },
    handleOrgCollapse(data) {
      const { id } = data
      this.expandedOrg = this.expandedOrg.filter((item) => item !== id)
    },

    handleOrgClick(data) {
      if (data.accessLevel === "ReadOnly") {
        this.$refs.tree.setCurrentKey(this.currentOrg)
        return
      }
      this.pageData.pageNo = 1
      this.currentOrg = data.id
      this.loadUserData()
    },

    handleOrgEdit(data) {
      this.$refs.orgForm.editForm(data)
    },

    @Confirm({ message: i18n.t("sys.confirm_to_delete_department") })
    handleOrgDelete(data) {
      deleteHmorg({
        id: data.id,
      }).then((res) => {
        this.loadOrgData()
      })
    },

    handleReset() {
      this.queryData = {
        ...defaultQueryData,
      }
      this.loadUserData()
    },

    loadUserData() {
      const orgId = this.$refs.tree.getCurrentKey()
      getHmuserPageListwithpermission({
        ...this.queryData,
        ...this.pageData,
        orgIds: orgId,
      }).then((res) => {
        this.tableData = res.data
        this.total = res.totalCount
      })
    },

    handleCreate() {
      const orgId = this.$refs.tree.getCurrentKey()
      this.$router.push({
        path: "/organizationPermission/organization/user",
        query: {
          org: orgId,
        },
      })
    },

    handleExport() {
      const orgId = this.$refs.tree.getCurrentKey()
      getHmuserExport(
        {
          ...this.queryData,
          ...this.pageData,
          orgId,
        },
        {
          responseType: "blob",
        }
      ).then((res) => {
        downloadFileStream(res.data, "组织架构导出列表.xlsx")
      })
    },

    handleTemplateDownload() {
      getHmuserDownloadexcel({
        responseType: "blob",
      }).then((res) => {
        downloadFileStream(res.data, "组织架构导入模板.xlsx")
      })
    },

    handleImportOk() {
      this.$message.success(this.$t("sys.operation_success"))
      this.loadOrgData()
      this.loadUserData()
    },

    handleSort(record) {
      this.$refs.sortForm.editForm({
        id: record.id,
        orgId: this.$refs.tree.getCurrentKey(),
        serialNum: record.serialNum,
      })
    },

    handleEdit(record) {
      this.$router.push({
        path: "/organizationPermission/organization/user",
        query: {
          id: record.id,
        },
      })
    },

    handleUserSelect(val) {
      this.userSelected = val
    },

    @Confirm({ message: i18n.t("sys.confirm_to_quit_in_batch") })
    handleBatchQuit() {
      const ids = this.userSelected.map((item) => item.id)
      putHmuserQuit({
        ids,
      }).then((res) => {
        this.$refs.table.clearSelection()
        this.loadUserData()
        this.$message.success(this.$t("sys.operation_success"))
      })
    },

    handleDelete(record) {
      deleteHmuser([record.id]).then((res) => {
        this.loadUserData()
        this.$message.success(this.$t("sys.operation_success"))
      })
    },

    @Confirm({ message: i18n.t("sys.confirm_to_delete_person_in_batch") })
    handleBatchDelete() {
      const ids = this.userSelected.map((item) => item.id)
      deleteHmuser(ids).then((res) => {
        this.$message.success(this.$t("sys.operation_success"))
        this.loadUserData()
        this.$refs.table.clearSelection()
      })
    },

    @Confirm({ message: i18n.t("sys.confirm_to_reset_password_in_batch") })
    handleBatchReset() {
      const ids = this.userSelected.map((item) => item.id)
      putHmuserResetpsd(ids).then((res) => {
        // 重置密码以后不用拉取新数据
        this.$message.success(this.$t("sys.operation_success"))
        this.$refs.table.clearSelection()
      })
    },

    handleBatchMove() {
      const ids = this.userSelected.map((item) => item.id)
      this.$refs.moveForm.editForm({
        ids,
        srcId: this.$refs.tree.getCurrentKey(),
      })
    },

    handleHigherChange(data) {
      const { item } = data
      if (item.length === 0) {
        this.$message.warning(this.$t("sys.select_immediate_superior"))
        return
      }
      const { id } = item[0]
      putHmuserResethigher({
        higherId: id,
        userIds: this.userSelected.map((item) => item.id),
      }).then((res) => {
        this.$refs.table.clearSelection()
        // 批量修改上级不用刷新
        this.$message.success(this.$t("sys.operation_success"))
        this.$refs.SelectHigherModal.close()
      })
    },

    handleBatchHigher() {
      this.$refs.SelectHigherModal.open()
    },

    //授予用户席位
    @Confirm({ message: i18n.t("sys.confirm_to_grant_seat_in_batch") })
    async handleBatchGrantSeat() {
      const ids = this.userSelected.map((item) => item.id)
      await distributionSeatUids({ userIds: ids.join(",") })
      await this.$store.dispatch("GetLicenseInfoDto")
      this.$refs.table.clearSelection()
      this.loadUserData()
      this.$message.success(this.$t("sys.operation_success"))
    },

    //取消用户席位
    @Confirm({ message: i18n.t("sys.confirm_to_cancel_seat_in_batch") })
    async handleBatchCancelSeat() {
      const ids = this.userSelected.map((item) => item.id)
      await unbindSeatUids({ userIds: ids.join(",") })
      await this.$store.dispatch("GetLicenseInfoDto")
      this.$refs.table.clearSelection()
      this.loadUserData()
      this.$message.success(this.$t("sys.operation_success"))
    },
    handleUserBatchCommand(command) {
      if (command === "quit") {
        this.handleBatchQuit()
      } else if (command === "delete") {
        this.handleBatchDelete()
      } else if (command === "reset") {
        this.handleBatchReset()
      } else if (command === "move") {
        this.handleBatchMove()
      } else if (command === "higher") {
        this.handleBatchHigher()
      } else if (command === "grantSeat") {
        this.handleBatchGrantSeat()
      } else if (command === "cancelSeat") {
        this.handleBatchCancelSeat()
      }
    },

    handleSelectHigherNodeChange(org) {
      return getHmuserPageListwithpermission({
        pageSize: 100000,
        pageNo: 1,
        orgId: org.id,
        status: 1,
      }).then((res) => {
        return res.data
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.user-status-badge {
  margin-top: 12px;
  margin-right: 5px;
}
.org-name-tag {
  margin-top: 5px;
  margin-right: 5px;
  background-color: #f4f4f5;
  border: 1px solid #e9e9eb;
  color: #909399;
  padding: 0 8px;
  line-height: 22px;
  box-sizing: border-box;
  border-radius: 4px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-inline-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.dept-manager--desc {
  font-weight: bold;
  font-size: 12px;
  opacity: 0.5;
}

::v-deep
  .el-tree--highlight-current
  .el-tree-node.is-current
  > .el-tree-node__content {
  background-color: #409eff;
  //background-color: rgba(64,158,255, 0.85);
}
::v-deep .el-card__header {
  padding: 8px 10px;
  text-align: center;
}
</style>
